package com.mask.im.business.controller;

import com.mask.im.business.annotation.OptLog;
import com.mask.im.business.model.dto.*;
import com.mask.im.business.model.vo.ConditionVO;
import com.mask.im.business.common.model.RestResponse;
import com.mask.im.business.model.vo.WebsiteConfigVO;
import com.mask.im.business.service.LiveChatService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.validation.Valid;

import java.util.List;

import static com.mask.im.business.common.constant.OptTypeConstant.UPDATE;
import static com.mask.im.business.common.constant.OptTypeConstant.UPLOAD;

@Api(tags = "系统模块")
@RestController
public class LiveChatController {

	@Autowired
	private LiveChatService liveChatService;

	@ApiOperation(value = "上报访客信息")
	@PostMapping("/report")
	public RestResponse<?> report() {
		liveChatService.report();
		return RestResponse.ok();
	}

	@ApiOperation("获取当前所在地址")
	@GetMapping("/users/current/address")
	public RestResponse<String> currentAddress(){
		return liveChatService.currentAddress();
	}


	@ApiOperation(value = "获取后台信息")
	@GetMapping("/admin")
	public RestResponse<LiveChatAdminDTO> getBlogBackInfo() {
		return RestResponse.ok(liveChatService.getBlogBackInfo());
	}

	@ApiOperation("用户可视化数据")
	@GetMapping("/users")
	public RestResponse<LiveChatUserDTO> getUserData(){
		return liveChatService.getUserData();
	}


	@OptLog(optType = UPDATE)
	@ApiOperation(value = "更新网站配置")
	@PutMapping("/admin/website/config")
	public RestResponse<?> updateWebsiteConfig(@Valid @RequestBody WebsiteConfigVO websiteConfigVO) {
		liveChatService.updateWebsiteConfig(websiteConfigVO);
		return RestResponse.ok();
	}


	@ApiOperation(value = "获取用户区域分布")
	@GetMapping("/admin/users/area")
	public RestResponse<List<UserAreaDTO>> listUserAreas(ConditionVO conditionVO) {
		return RestResponse.ok(liveChatService.listUserAreas(conditionVO));
	}


	@ApiOperation(value = "获取网站配置")
	@GetMapping("/admin/website/config")
	public RestResponse<WebsiteConfigDTO> getWebsiteConfig() {
		return RestResponse.ok(liveChatService.getWebsiteConfig());
	}

	@ApiOperation(value = "前台用户获取部分网站配置")
	@GetMapping("/users/website/config")
	public RestResponse<WebsiteConfigUserDTO> getUsersWebsiteConfig() {
		return RestResponse.ok(liveChatService.getUsersWebsiteConfig());
	}

	@OptLog(optType = UPLOAD)
	@ApiOperation(value = "上传配置图片")
	@ApiImplicitParam(name = "file", value = "图片", required = true, dataType = "MultipartFile")
	@PostMapping("/admin/config/images")
	public RestResponse<?> savePhotoAlbumCover(MultipartFile file) {
//		return fileUploadContext.execute("oss", file);
		return null;

	}

	@ApiOperation("获取系统公告内容")
	@GetMapping("/users/config/notice")
	public RestResponse<String> broadcastContent(){
		return liveChatService.broadcastContent();
	}
}
